from django.http import JsonResponse


def response_change(response):
    response["Access-Control-Allow-Origin"] = "*"
    response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
    response["Access-Control-Max-Age"] = "1000"
    response["Access-Control-Allow-Headers"] = "*"
    response["Access-Control-Allow-Credentials"] = True
    return response


RESP_TITLE = ["error", "message", "data","successs"]

import logging

from comment.errorcode import *
def err_response(error, message):
    logging.info("[{}]:{}".format(error, message))
    resp = {
        "error": error,
        "message": message,
        "data": None,
        "success":0
    }
    return JsonResponse(resp)


def format_response(func):
    def response_change(request):
        response = func(request)
        response["Access-Control-Allow-Origin"] = "*"
        response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
        response["Access-Control-Max-Age"] = "1000"
        response["Access-Control-Allow-Headers"] = "*"
        response["Access-Control-Allow-Credentials"] = True
        return response

    return response_change
